/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 1, or (at your option)
** any later version.

** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.

** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "ia_indicator.h"

#include <QPainter>
#include <QPen>
#include <QBrush>
#include <QColor>

IAIndicator::IAIndicator(QWidget * parent)
    : QWidget(parent),
      curState(false)
{
    setMinimumSize(100, 20);
}

void IAIndicator::setState(bool state)
{
    if (state == curState)
        return;
    curState = state;
    update();
}

void IAIndicator::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setPen(QPen(QColor("black")));
    QString msg;
    if (curState) {
        painter.setBrush(QBrush(QColor("green")));
        msg = tr("Connected");
    } else {
        painter.setBrush(QBrush(QColor("red")));
        msg = tr("Disconnected");
    }
    painter.drawRect(QRectF(0.0, 0.0, 100.0, 19.0));
    painter.drawText(QRectF(0.0, 0.0, 100.0, 19.0),
                     Qt::AlignHCenter | Qt::AlignVCenter,
                     msg);
}
